package com.woniuxy.credit_loans.accounting_shi.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.credit_loans.accounting_shi.dto.LiuDto;
import com.woniuxy.credit_loans.accounting_shi.service.AccountService;
import com.woniuxy.credit_loans.accounting_shi.service.ContractInfoService;
import com.woniuxy.credit_loans.accounting_shi.service.DebitInfoService;
import com.woniuxy.credit_loans.accounting_shi.vo.WeiDaVo;
import com.woniuxy.credit_loans.entity.Account;
import com.woniuxy.credit_loans.entity.DebitInfo;
import com.woniuxy.credit_loans.entity.ContractInfo;
import com.woniuxy.credit_loans.entity.ContractInfo;
import com.woniuxy.credit_loans.mapper.AccountMapper;
import com.woniuxy.credit_loans.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/contracts")
public class ContracInfoController {
    @Autowired
    private ContractInfoService contractInfoService;
    @Autowired
    private AccountService accountService;
    @Autowired
    private DebitInfoService debitInfoService;
    @PostMapping("/aall")
    public Result a1(){
        List<Account> accounts = accountService.selectAll();
        return Result.ok().data("list",accounts);
    }
    @PostMapping("/heall")
    public Result a2(@RequestBody LiuDto liuDto){
        PageHelper.startPage(liuDto.getCurrentPage(), liuDto.getPageSize(),true);
        List<WeiDaVo> accounts = contractInfoService.selectByName("终审通过", liuDto.getRealName());
        PageInfo pageInfo=new PageInfo(accounts);
        return Result.ok().data("list",accounts).data("total",pageInfo.getTotal());
    }
    @PostMapping("/all")
    public Result c1(){
        List<WeiDaVo> weiDaVos = contractInfoService.selectAllById("放款审批");
        return Result.ok().data("list",weiDaVos);
    }
    @PostMapping("/yiall")
    public Result c2(){
        List<WeiDaVo> weiDaVos = contractInfoService.selectAllById("还款中");
        return Result.ok().data("list",weiDaVos);
    }
    @GetMapping("{id}")
    public Result c3(@PathVariable Long id){
        WeiDaVo weiDaVo = contractInfoService.selectById(id);
        Account account = accountService.selectAccountBankAccount(id, weiDaVo);
        return Result.ok();
    }
    @GetMapping("/he/{id}")
    public Result c4(@PathVariable Long id){
        WeiDaVo weiDaVo = contractInfoService.selectByHeId(id);
        return Result.ok().data("hetong",weiDaVo);
    }
    @PostMapping("/gai")
    public Result c5(@RequestBody DebitInfo weiDaVo){
        int i = debitInfoService.updateByPrimaryKeySelective(weiDaVo);
        return Result.ok();
    }
    @PostMapping("/addOne")
    public Result c4(String diNumber){
        ContractInfo contractInfo = new ContractInfo();
        contractInfo.setDiNumber(diNumber);
        contractInfoService.insertSelective(contractInfo);
        return Result.ok();
    }

}
